﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KCMS.BusinessLogic.Models;
using KCMS.Web.Models;
using System.Web.Routing;
namespace KCMS.Controllers
{
    public class MenuItemController : Controller
    {
        //
        // GET: /MenuItem/

        public ActionResult Show(MenuItemViewModel item)
        {
            item.RouteValues = this.GenerateRouteValues(item);
            item.HtmlAttributes = this.GenerateHtmlAttributes(item);
            return PartialView(item);
        }
        private Dictionary<string, object> GenerateRouteValues(MenuItemViewModel item)
        {
            Dictionary<string, object> routeVals = new Dictionary<string, object>();
            if (item.Area != null) { routeVals.Add("area", item.Area); }
            if (item.ContentCategory != null) { routeVals.Add("category", item.ContentCategory); }
            if ((item.ContentCode == null))
            {
                if (item.ContentId != null)
                    if (item.ContentId != Guid.Empty)
                    {
                        routeVals.Add("id", item.ContentId.ToString());
                    }
            }
            else
            {
                routeVals.Add("code", (object)item.ContentCode);
                if (item.ContentIndex != 0) routeVals.Add("index", (object)item.ContentIndex);
            }
            return routeVals;
        }
        private Dictionary<string, object> GenerateHtmlAttributes(MenuItemViewModel item)
        {
            Dictionary<string, object> routeVals = new Dictionary<string, object>();
            if (item.HtmlClass != null) { routeVals.Add("class", item.HtmlClass); }
            if (item.HtmlId != null) { routeVals.Add("id", item.HtmlId); }
            return routeVals;
        }

    }
}
